package com.example.sunmiv1.adapter.good;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GoodSortAdapter extends BaseAdapter {

    private List<String> list;
    private ViewHolder viewHolder;

    private int select;

    public GoodSortAdapter(List<String> list) {
        this.list = list;
    }

    public void setSelect(int select) {
        this.select = select;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.good_sort_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (position == select) {
            viewHolder.goodSortTv.setTextColor(parent.getContext().getResources().getColor(R.color.FF5E6E));
            viewHolder.goodSortTv.setBackgroundResource(R.drawable.ff5e6e_border);
        } else {
            viewHolder.goodSortTv.setTextColor(parent.getContext().getResources().getColor(R.color.text_999));
            viewHolder.goodSortTv.setBackgroundResource(R.drawable.eee_border);
        }
        viewHolder.goodSortTv.setText(list.get(position));
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.goodSort_tv)
        TextView goodSortTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
